<template>
  <ui-tabs
    v-model="innerValue"
    class="ui-tabbar"
  >
    <ui-tabs-pane
      v-for="(item, index) in items"
      :key="index"
      :name="item[nameField]"
      :label="item[labelField]"
    >
    </ui-tabs-pane>
  </ui-tabs>
</template>
<script>
import { Tabs, TabsPane } from '../tabs'

export default {
  name: 'UiTabbar',
  components: {
    UiTabs: Tabs,
    UiTabsPane: TabsPane
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    size: {
      type: String,
      default: 'mini',
      validator(value) {
        return ['mini', 'small'].includes(value)
      }
    },
    labelField: {
      type: String,
      default: 'label'
    },
    nameField: {
      type: String,
      default: 'name'
    },
    items: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    innerValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    onlyOne() {
      return this.items.length === 1
    }
  }
}
</script>
<style lang="less">
</style>
